import moment from 'moment'
import { Request, Response } from 'express';
import type { AnalysisData, DataItem } from '@/pages/Index/data.d';
import { random } from 'lodash';

const waitTime = (time: number = 100) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(true);
      }, time);
    });
  };

let salesData ={
    title:'总销额',
    saleTotal:Math.floor(Math.random() * 10000),
    saleTB: Math.floor(Math.random() * 10),
    saleHB: Math.floor(Math.random() * 10),
    saleDay: Math.floor(Math.random() * 1000),
    desc:'@ctitle(10)',
}

let visitList = []
for (let i = 0; i < 10; i += 1) {
    visitList.push({
      xValue: moment().subtract(i,'d').format('YYYY-MM-DD'),
      yValue: Math.floor(Math.random() * 1000),
    });
}
let visitData = {
    title:'访问量',
    data:visitList,
}

let orderNumList = []
for (let i = 0; i < 10; i += 1) {
    orderNumList.push({
      timePeriod: moment().subtract(i,'d').format('YYYY-MM-DD'),
      value: Math.floor(Math.random() * 10),
    });
}
let orderNumData = {
    title:'支付笔数',
    data:orderNumList
}

let oprationData = {
    title:'运营活动效果',
    data:{year: '1958 年',value: 48}
}

// let searchData = [];
// for (let i = 0; i < 50; i += 1) {
//     searchData.push({
//         index: i + 1,
//         keyword: `搜索关键词-${i}`,
//         count: Math.floor(Math.random() * 1000),
//         range: Math.floor(Math.random() * 100),
//         status: Math.floor((Math.random() * 10) % 2),
//     });
// }
let saleEData = []
for (let i = 0; i < 12; i += 1) {
  saleEData.push({
    xValue: i+1 + "月",
    yValue: Math.floor(Math.random() * 100),
  });
}
let visitRankData = []
for (let i = 0; i < 50; i += 1) {
  visitRankData.push({
    name: "工专路"+i,
    value: Math.floor(Math.random() * 100000),
  });
}
let saleTypeData = []
for (let i = 1; i < 6; i += 1) {
  saleTypeData.push({
    type: i>4?"其他":"分类"+i,
    value: Math.floor(Math.random() * 100000),
  });
}

let tableData = []
for (let i = 0; i < 20; i += 1) {
  tableData.push({
    index: i+1,
    keyword: '关键词'+i,
    count:Math.floor(Math.random() * 1000),
    range:Math.floor(Math.random() * 100),
  });
}


let searchData = []
for (let i = 0; i < 2; i += 1) {
  let searchList = []
  for (let j = 0; j < 12;j += 1) {
    searchList.push({
      timePeriod: j+1+'月',
      value: Math.floor(Math.random() * 100),
    });
  }
  searchData.push({
    title: i==0?'搜索用户数':'人均搜索次数',
    total: Math.floor(Math.random() * 1000),
    totalTB: Math.floor(Math.random() * 10),
    data:searchList
  });

}


const fakeChartData: AnalysisData = {
    salesData,
    visitData,
    orderNumData,
    oprationData,
    searchData,
    saleEData,
    visitRankData,
    saleTypeData,
    tableData,
  };


async function getFakeCaptcha(req: Request, res: Response) {
    await waitTime(2000);
    return res.json({success: true,data:fakeChartData});
}

export default{
    'GET  /api/fake_analysis_chart_data': getFakeCaptcha,
}
